#include "std.hpp"
#include "Ynbw.hpp"

void Ynbw::newGame()
{
  try
  {
FUNCTION

    std::cout << "New Game\n";

    unsigned int localNumberPlayers;
    bool enteringPlayers = true;
    while(enteringPlayers)
    {
      std::cout << "Enter number of players (max " << MAXIMUM_PLAYERS_ << ", 0 to cancel): ";
      std::cin >> localNumberPlayers;

      if(localNumberPlayers == 0) throw YnbwException(EXCEPTION_SUCCESS);

      if(localNumberPlayers < MINIMUM_PLAYERS_)
      {
        std::cerr << "You can't have " << localNumberPlayers << " player(s)!\n";
        continue;
      }

      if(localNumberPlayers > MAXIMUM_PLAYERS_)
      {
        std::cerr << "You are only allowed " << MAXIMUM_PLAYERS_ << " players, ";
        std::cerr << "but you asked for " << localNumberPlayers << " players!\n";
        continue;
      }
      break;
    }

    if(std::cin.peek() == '\n') std::cin.ignore(1, '\n');

    for(unsigned int i = 0; i < localNumberPlayers; i++)
    {
      char temporaryName[256];
      Player *temporaryPlayer;
      std::cout << "What is player " << (i + 1) << "\'s name? ";
      std::cin.getline(temporaryName, 256, '\n');
      temporaryPlayer = new Player(temporaryName, false);
      if(temporaryPlayer == 0)
      {
        throw YnbwException(EXCEPTION_OUTOFMEMORY);
      }
      addPlayer(temporaryPlayer);
    }
    playersStillIn_ = numberPlayers_;
  }
  catch(...)
  {
    throw;
  }
}
